package com.lzx.iteam.adapter;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ImageSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.lzx.iteam.ImagePagerActivity;
import com.lzx.iteam.R;
import com.lzx.iteam.TalkListActivity;
import com.lzx.iteam.bean.TalkListData;
import com.lzx.iteam.emotion.gif.AnimatedGifDrawable;
import com.lzx.iteam.emotion.gif.AnimatedImageSpan;
import com.lzx.iteam.widget.gridimg.MyGridView;
import com.lzx.iteam.net.*;
import com.lzx.iteam.util.*;
import com.lzx.iteam.widget.TextViewSpan;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Megan on 15/10/14.
 */
public class TalkListAdapter extends BaseAdapter {

    private Context mContext;
    private String mAction;
    private ArrayList<TalkListData> mTalkListDatas;
    /*private TalkListCommentAdapter commentAdapter;
    private PraiseNameListAdapter praiseNameListAdapter;*/
    private EventImageAdapter imageAdapter;
    private ArrayList<String> mImages;
    private ArrayList<String> mNameCard = new ArrayList<String>();
    ViewHolder viewHolder;
    //    String[] oriImgUrl = null;
    private String mPraise;
    private int mPosition;

    private PreferenceUtil mPreferenceUtil;
    private String userId;
    private AllDialogUtil mDialogUtil;
    private final int ADD_PRAISE = 1001;
    public final int DETELE_COMMENT = 1002;
    public Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case ADD_PRAISE:
                    if (msg.arg1 == 0) {
                        mPraise = (String) msg.obj;
                        if ("1".equals(mPraise)) {
                            mTalkListDatas.get(mPosition).isPraise = "1";
                            Map<String, String> userData = new HashMap<String, String>();
                            userData.put(Constants.TALK_USER_ID, userId);
                            userData.put(Constants.TALK_USER_NAME, mNameCard.get(0));
                            userData.put(Constants.TALK_TYPE, "1");
                            if (mTalkListDatas.get(mPosition).praises == null) {
                                mTalkListDatas.get(mPosition).praises = new ArrayList<Map<String, String>>();
                                mTalkListDatas.get(mPosition).praises.add(userData);
                            } else {
                                mTalkListDatas.get(mPosition).praises.add(userData);
                            }

                        } else {
                            for (int i = 0; i < mTalkListDatas.get(mPosition).praises.size(); i++) {
                                if (mTalkListDatas.get(mPosition).praises.get(i).get(Constants.TALK_USER_ID).equals(userId)) {
                                    mTalkListDatas.get(mPosition).praises.remove(i);
                                }
                            }
                            mTalkListDatas.get(mPosition).isPraise = "0";
                        }
                        Log.d("talkListData.position", mPosition + "");
                        notifyDataSetChanged();
                        TalkListCenter.getInstance(mContext).upDateCloudTalkData(true, mPraise, mTalkListDatas.get(mPosition).praises, mTalkListDatas.get(mPosition).talkId);
                    }
                    break;
                case DETELE_COMMENT:
                    if (msg.arg1 == 0) {
                        Map<String, String> comment = (Map<String, String>) msg.obj;
                        mTalkListDatas.get(mPosition).comments.remove(comment);
                        notifyDataSetChanged();
                        TalkListCenter.getInstance(mContext).upDateCloudTalkData(false, null, mTalkListDatas.get(mPosition).comments, mTalkListDatas.get(mPosition).talkId);

                    }
                    break;
            }
        }
    };


    public TalkListAdapter(Context mContext, String action) {
        this.mContext = mContext;
        mPreferenceUtil = PreferenceUtil.getInstance(mContext);
        userId = mPreferenceUtil.getString(PreferenceUtil.CLIENT_USEID, "－1");
        mDialogUtil = AllDialogUtil.getInstance((TalkListActivity) mContext);
        mNameCard = (ArrayList<String>) mPreferenceUtil.getCloudContact(Constants.CONTACT_NAME_CARD);
        /*commentAdapter = new TalkListCommentAdapter(mContext);
        praiseNameListAdapter = new PraiseNameListAdapter(mContext);*/
        mAction = action;
    }

    public void bindData(ArrayList<TalkListData> talkListDatas) {
        //this.mTalkListDatas = talkListDatas;
        if (this.mTalkListDatas != null) {
            this.mTalkListDatas.clear();
            this.mTalkListDatas.addAll(talkListDatas);
        } else {
            this.mTalkListDatas = new ArrayList<TalkListData>();
            this.mTalkListDatas.addAll(talkListDatas);
        }
        notifyDataSetChanged();
        Log.d("TalkListAdapter","notifyDataSetChanged");
    }

    @Override
    public int getCount() {
        return mTalkListDatas == null ? 0 : mTalkListDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mTalkListDatas == null ? null : mTalkListDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        if (mTalkListDatas != null) {
            final TalkListData talkListData = mTalkListDatas.get(position);
            if (convertView == null) {
                viewHolder = new ViewHolder();
                convertView = LayoutInflater.from(mContext).inflate(R.layout.talk_list_item, null);
                viewHolder.mIvUserImage = (ImageView) convertView.findViewById(R.id.talk_list_item_user_img);
                viewHolder.mIvComment = (ImageView) convertView.findViewById(R.id.iv_talk_list_item_comment);
                viewHolder.mIvPraise = (ImageView) convertView.findViewById(R.id.iv_talk_list_item_praise);
                viewHolder.mTvUserName = (TextView) convertView.findViewById(R.id.talk_list_item_user_name);
                viewHolder.mTvContent = (TextView) convertView.findViewById(R.id.talk_list_item_content);
                viewHolder.mTvTime = (TextView) convertView.findViewById(R.id.talk_list_item_user_time);
                viewHolder.mTvAddOnePraise = (TextView) convertView.findViewById(R.id.tv_talk_list_item_praise_add_one);
                viewHolder.mGvImageGrid = (MyGridView) convertView.findViewById(R.id.talk_list_item_gv_image);
//                viewHolder.mLvPraiseName = (ListView) convertView.findViewById(R.id.lv_talk_list_item_praise_list);
//                viewHolder.mLlPraiseLayout = (LinearLayout) convertView.findViewById(R.id.talk_list_praise_layout);
//                viewHolder.mLvCommentList = (MyListView) convertView.findViewById(R.id.lv_talk_list_item_comment_list);
                viewHolder.mLlReplyLayout = (LinearLayout) convertView.findViewById(R.id.talk_list_reply_layout);
                viewHolder.mLlPraiseLayout = (LinearLayout) convertView.findViewById(R.id.talk_list_praise_layout);
                viewHolder.mLlCommentLayout = (LinearLayout) convertView.findViewById(R.id.ll_talk_list_item_comment_list);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            if (talkListData.thumbImage != null) {
                viewHolder.mGvImageGrid.setTag(talkListData.thumbImage + "@" + talkListData.oriImage);
            }
            viewHolder.mIvPraise.setTag(talkListData.talkId + "@" + talkListData.isPraise);
            viewHolder.mIvComment.setTag(talkListData.talkId);
            viewHolder.mTvUserName.setText(talkListData.uName);
//            viewHolder.mLlReplyLayout.setTag(talkListData.talkId);
//            viewHolder.mLlPraiseLayout.setTag(talkListData.praises);
//            viewHolder.mLlCommentLayout.setTag(talkListData.comments);
            if (StringUtil.isEmpty(talkListData.text)) {
                viewHolder.mTvContent.setVisibility(View.GONE);
            } else {
                viewHolder.mTvContent.setVisibility(View.VISIBLE);
                SpannableStringBuilder sb = handler(viewHolder.mTvContent,
                        talkListData.text);
                viewHolder.mTvContent.setText(sb);
            }

            viewHolder.mTvTime.setText(DateUtil.getChatTime(Long.parseLong(talkListData.createTime) * 1000));
            /*if (talkListData.praises != null && talkListData.praises.size() > 0) {
                viewHolder.mLlPraiseLayout.setVisibility(View.VISIBLE);
                praiseNameListAdapter.bindData(talkListData.praises);
                viewHolder.mLvPraiseName.setAdapter(praiseNameListAdapter);
            } else {
                viewHolder.mLlPraiseLayout.setVisibility(View.GONE);
            }
            if (talkListData.comments != null && talkListData.comments.size() > 0) {
                viewHolder.mLlPraiseLayout.setVisibility(View.VISIBLE);
                commentAdapter.bindData(talkListData.comments);
                viewHolder.mLvCommentList.setAdapter(commentAdapter);
            } else {
                viewHolder.mLvCommentList.setVisibility(View.GONE);

            }*/
            if ((talkListData.praises != null && talkListData.praises.size() > 0) || (talkListData.comments != null && talkListData.comments.size() > 0)) {
                viewHolder.mLlReplyLayout.setVisibility(View.VISIBLE);
                if (talkListData.praises != null && talkListData.praises.size() > 0) {
                    viewHolder.mLlPraiseLayout.setVisibility(View.VISIBLE);
                    viewHolder.mLlPraiseLayout.removeAllViews();
                    ImageView praiseIcon = new ImageView(mContext);
                    praiseIcon.setPadding(0, 0, 8, 0);
                    praiseIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.praise));
                    viewHolder.mLlPraiseLayout.addView(praiseIcon);
                    for (int i = talkListData.praises.size() - 1; i > -1; i--) {
                        final Map<String, String> praiseMap = talkListData.praises.get(i);
                        if (talkListData.praises.size() - i < 4) {
                            TextView praise = new TextView(mContext);
                            praise.setMovementMethod(LinkMovementMethod.getInstance());
                            praise.setTextColor(mContext.getResources().getColor(
                                    R.color.talk_item_comment_name));
                            praise.setTextSize(14);
                            //praise.setPadding(2, 0, 2, 0);
                            SpannableString user = new SpannableString(praiseMap.get(Constants.TALK_USER_NAME));//回复人的名字
                            TextViewSpan clickableSpan1 = new TextViewSpan(praiseMap.get(Constants.TALK_USER_NAME), mContext, 0, 0);
                            clickableSpan1.setInfo(praiseMap);
                            user.setSpan(clickableSpan1, 0, praiseMap.get(Constants.TALK_USER_NAME).length(),
                                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            praise.append(user);
                            if (i == talkListData.praises.size() - 3 || i == 0) {
                                
                            } else {
                                praise.append("、");
                            }
//                            praise.setOnClickListener(new View.OnClickListener() {
//                                @Override
//                                public void onClick(View view) {
//                                    Toast.makeText(mContext, praiseMap.get(Constants.TALK_USER_NAME), Toast.LENGTH_LONG).show();
//                                }
//                            });
                            viewHolder.mLlPraiseLayout.addView(praise);
                        } else {
                            break;
                        }
                    }
                    TextView praiseCount = new TextView(mContext);
                    praiseCount.setTextColor(mContext.getResources().getColor(
                            R.color.talk_item_comment_content));
                    praiseCount.setTextSize(14);
                    praiseCount.setPadding(2, 0, 2, 0);
                    if (talkListData.praises.size() > 3) {
                        praiseCount.setText("等" + talkListData.praises.size() + "人点赞");
                    } else {
                        praiseCount.setText("点赞");
                    }
                    viewHolder.mLlPraiseLayout.addView(praiseCount);

                } else {
                    viewHolder.mLlPraiseLayout.setVisibility(View.GONE);
                }
                if (talkListData.comments != null && talkListData.comments.size() > 0) {
                    viewHolder.mLlCommentLayout.setVisibility(View.VISIBLE);
                    viewHolder.mLlCommentLayout.removeAllViews();
                    for (int i = 0; i < talkListData.comments.size(); i++) {
                        final Map<String, String> commentMap = talkListData.comments.get(i);
                        TextView comment = new TextView(mContext);
                        comment.setMovementMethod(LinkMovementMethod.getInstance());
                        comment.setTextColor(mContext.getResources().getColor(
                                R.color.talk_item_comment_content));
                        comment.setTextSize(14);
                        String commentName = commentMap.get(Constants.TALK_USER_NAME);
                        SpannableString commentTo = new SpannableString(commentName);
                        TextViewSpan clickableSpan = new TextViewSpan(commentName, mContext, 0, 0);
                        clickableSpan.setInfo(commentMap);
                        commentTo.setSpan(clickableSpan, 0, commentName.length(),
                                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        if (StringUtil.isEmpty(commentMap.get(Constants.TALK_REPLY_NAME))) {
                            comment.append(commentTo);
                            comment.append(":");
                            SpannableStringBuilder ssb = handler(comment,
                                    commentMap.get(Constants.TALK_COMMENT));
                            comment.append(ssb);
                        } else {
                            String replyName = commentMap.get(Constants.TALK_REPLY_NAME);
                            SpannableString replyTo = new SpannableString(replyName);//回复人的名字
                            TextViewSpan clickableSpan1 = new TextViewSpan(replyName, mContext, 0, 0);

                            Map<String, String> replyData = new HashMap<String, String>() ;
                            replyData.put(Constants.TALK_USER_ID,commentMap.get(Constants.TALK_REPLY_ID));

                            clickableSpan1.setInfo(replyData);
                            replyTo.setSpan(clickableSpan1, 0, replyName.length(),
                                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            comment.setText(commentTo);
                            comment.append("回复");
                            comment.append(replyTo);
                            comment.append(":");
                            SpannableStringBuilder ssb = handler(comment,
                                    commentMap.get(Constants.TALK_COMMENT));
                            comment.append(ssb);
                        }
                        comment.setBackgroundResource(R.drawable.talk_comment_bg_selector);
                        //comment.setBackgroundColor(mContext.getResources().getColor(R.color.talk_comment_selector));
                       /* CustomLinkMovementMethod link = (CustomLinkMovementMethod) CustomLinkMovementMethod.getInstance();
                        link.setOnTextClickListener(new CustomLinkMovementMethod.TextClickedListener() {
                            @Override
                            public void onTextClicked() {
                                if (commentMap.get(Constants.TALK_USER_ID).equals(userId)) {
                                    showDeleteTalkCommentDlg(commentMap);
                                    mPosition = position;
                                } else {
                                    Map<String, String> replyMap = new HashMap<String, String>();
                                    replyMap.put(Constants.TALK_USER_ID, userId);
                                    replyMap.put(Constants.TALK_USER_NAME, mNameCard.get(0));
                                    replyMap.put(Constants.TALK_ID, talkListData.talkId);
                                    replyMap.put(Constants.TALK_REPLY_ID, commentMap.get(Constants.TALK_USER_ID));
                                    replyMap.put(Constants.TALK_REPLY_NAME, commentMap.get(Constants.TALK_USER_NAME));
                                    replyMap.put(Constants.TALK_TYPE, "3");
                                    ((TalkListActivity) mContext).showBottomLayout(replyMap, position);
                                }
                            }
                        });
                        comment.setMovementMethod(link);*/
                        comment.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (commentMap.get(Constants.TALK_USER_ID).equals(userId)) {
                                    showDeleteTalkCommentDlg(commentMap);
                                    mPosition = position;
                                } else {
                                    Map<String, String> replyMap = new HashMap<String, String>();
                                    replyMap.put(Constants.TALK_USER_ID, userId);
                                    replyMap.put(Constants.TALK_USER_NAME, mNameCard.get(0));
                                    replyMap.put(Constants.TALK_ID, talkListData.talkId);
                                    replyMap.put(Constants.TALK_REPLY_ID, commentMap.get(Constants.TALK_USER_ID));
                                    replyMap.put(Constants.TALK_REPLY_NAME, commentMap.get(Constants.TALK_USER_NAME));
                                    replyMap.put(Constants.TALK_TYPE, "3");
                                    ((TalkListActivity) mContext).showBottomLayout(replyMap, position);
                                }
                            }
                        });
                        comment.setOnLongClickListener(new View.OnLongClickListener() {
                            @Override
                            public boolean onLongClick(View view) {
                                return true;
                            }
                        });
                        viewHolder.mLlCommentLayout.addView(comment);
                    }
                } else {
                    viewHolder.mLlCommentLayout.setVisibility(View.GONE);

                }
            } else {
                viewHolder.mLlReplyLayout.setVisibility(View.GONE);

            }

            if (viewHolder.mGvImageGrid.getTag() != null) {
                String thumbImage = ((String) viewHolder.mGvImageGrid.getTag()).split("@")[0];
                final String oriImage = ((String) viewHolder.mGvImageGrid.getTag()).split("@")[1];
                if (!StringUtil.isEmpty(thumbImage) && thumbImage.equals(talkListData.thumbImage)) {
                    String[] tmpImgUrl = thumbImage.split(",");
                    viewHolder.mGvImageGrid.setVisibility(View.VISIBLE);
                    imageAdapter = new EventImageAdapter(mContext, tmpImgUrl, talkListData.talkId);
                    viewHolder.mGvImageGrid.setAdapter(imageAdapter);

                } else {
                    viewHolder.mGvImageGrid.setVisibility(View.GONE);
                }

                if (!StringUtil.isEmpty(oriImage) && oriImage.equals(talkListData.oriImage)) {
                    viewHolder.mGvImageGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                            String[] images = oriImage.split(",");
                            Intent intent = new Intent(mContext, ImagePagerActivity.class);
                            intent.putExtra(Constants.IMAGE_ORIGIN, Constants.IMAGE_ORIGIN_URL_ARRAY);
                            mImages = new ArrayList<String>();
                            for (int i = 0; i < images.length; i++) {
                                mImages.add(images[i]);
                            }
                            intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, mImages);
                            intent.putExtra(ImagePagerActivity.EXTRA_THUME_IMAGES, talkListData.thumbImage);
                            intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, position);
                            mContext.startActivity(intent);
                        }
                    });
                }
            }

            ImageLoaderInterface.imageLoader.displayImage(talkListData.uImage, viewHolder.mIvUserImage, ImageLoaderInterface.optionHeadImage);
            viewHolder.mIvUserImage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mAction.equals(((TalkListActivity) mContext).CONTACTS_CIRCLE)) {
                        Intent intent1 = new Intent(mContext, TalkListActivity.class);
                        intent1.setAction(TalkListActivity.OTHER_PERSONAL_SPACE);
                        intent1.putExtra("set_user_id", talkListData.uId);
                        mContext.startActivity(intent1);
                    } else {
                        ArrayList<String> image = new ArrayList<String>();
                        image.add(talkListData.uImage.split("\\?")[0]);
                        Intent intent = new Intent(mContext, ImagePagerActivity.class);
                        intent.putExtra(Constants.IMAGE_ORIGIN, Constants.IMAGE_ORIGIN_URL_ARRAY);
                        intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, image);
                        mContext.startActivity(intent);
                    }
                }
            });
            if (viewHolder.mIvPraise.getTag() != null) {
                final String talkId = ((String) viewHolder.mIvPraise.getTag()).split("@")[0];
                final String isPraise = ((String) viewHolder.mIvPraise.getTag()).split("@")[1];
                if (!StringUtil.isEmpty(talkId) && talkId.equals(talkListData.talkId) && isPraise.equals(talkListData.isPraise)) {
                    if ("1".equals(isPraise)) {
                        viewHolder.mIvPraise.setImageDrawable(mContext.getResources().getDrawable(R.drawable.praise_pressed));
                    } else {
                        viewHolder.mIvPraise.setImageDrawable(mContext.getResources().getDrawable(R.drawable.praise_normal));
                    }
                    viewHolder.mIvPraise.setOnClickListener(
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    AddPraiseMsg(talkId);
                                    mPosition = position;
                                    Log.d("talkListData.position", mPosition + "");

                                }
                            }
                    );
                }
            }
            if (viewHolder.mIvComment.getTag() != null) {
                final String tagId = (String) viewHolder.mIvComment.getTag();
                if (!StringUtil.isEmpty(tagId) && tagId.equals(talkListData.talkId)) {
                    viewHolder.mIvComment.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Map<String, String> replyMap = new HashMap<String, String>();
                            replyMap.put(Constants.TALK_USER_ID, userId);
                            replyMap.put(Constants.TALK_USER_NAME, mNameCard.get(0));
                            replyMap.put(Constants.TALK_ID, tagId);
                            replyMap.put(Constants.TALK_TYPE, "2");
                            ((TalkListActivity) mContext).showBottomLayout(replyMap, position);

                        }
                    });
                }
            }

        }
        return convertView;

    }


    class ViewHolder {
        ImageView mIvUserImage;
        ImageView mIvComment;
        ImageView mIvPraise;
        TextView mTvUserName;
        TextView mTvContent;
        TextView mTvTime;
        TextView mTvAddOnePraise;
        MyGridView mGvImageGrid;

        LinearLayout mLlReplyLayout;
        LinearLayout mLlPraiseLayout;
        LinearLayout mLlCommentLayout;
//        ListView mLvPraiseName;
//        MyListView mLvCommentList;
//        LinearLayout mLlPraiseLayout;
    }

    private SpannableStringBuilder handler(final TextView gifTextView, String content) {
        SpannableStringBuilder sb = new SpannableStringBuilder(content);
        String regex = "(\\#\\[face/png/f_static_)\\d{3}(.png\\]\\#)";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(content);
        while (m.find()) {
            String tempText = m.group();
            try {
                String num = tempText.substring("#[face/png/f_static_".length(), tempText.length() - ".png]#".length());
                String gif = "face/gif/f" + num + ".gif";
                /**
                 * 如果open这里不抛异常说明存在gif，则显示对应的gif
                 * 否则说明gif找不到，则显示png
                 * */
                InputStream is = mContext.getAssets().open(gif);
                sb.setSpan(new AnimatedImageSpan(new AnimatedGifDrawable(is, new AnimatedGifDrawable.UpdateListener() {
                            @Override
                            public void update() {
                                gifTextView.postInvalidate();
                            }
                        })), m.start(), m.end(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                is.close();
            } catch (Exception e) {
                String png = tempText.substring("#[".length(), tempText.length() - "]#".length());
                try {
                    int resID = mContext.getResources().getIdentifier(png.split("/")[2].substring(0, png.split("/")[2].indexOf(".")), "drawable", mContext.getApplicationInfo().packageName);
                    sb.setSpan(new ImageSpan(mContext, BitmapFactory.decodeResource(mContext.getResources(), resID)), m.start(), m.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//                    sb.setSpan(new ImageSpan(mContext, BitmapFactory.decodeStream(mContext.getAssets().open(png))), m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
//                e.printStackTrace();
            }
        }
        return sb;
    }


    /**
     * 点赞
     *
     * @param talkId
     */
    private void AddPraiseMsg(String talkId) {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_TALK_ID, talkId));
        AddTalkCommentMsg message = new AddTalkCommentMsg(mHandler.obtainMessage(ADD_PRAISE), mContext);
        message.mApi = AsynHttpClient.API_TALK_LIKE;
        message.mParams = nvps;
        AsynHttpClient.getInstance(mContext).execTalkHttp(message);
    }


    private void deleteTalkComment(Map<String, String> comment) {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_TALK_ID, comment.get(Constants.TALK_ID)));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_TALK_ABOUT_ID, comment.get(Constants.TALK_ABOUT_ID)));
        DeleteTalkCommentMsg message = new DeleteTalkCommentMsg(mHandler.obtainMessage(DETELE_COMMENT), comment);
        message.mApi = AsynHttpClient.API_TALK_DEL_REPLY;
        message.mParams = nvps;
        AsynHttpClient.getInstance(mContext).execTalkHttp(message);
    }


    public void showDeleteTalkCommentDlg(final Map<String, String> comment) {
        String okText = mContext.getString(R.string.label_btn_delete);
        String cancelText = mContext.getString(R.string.cancel);
        mDialogUtil.titleDeleteMsgStyle(okText, cancelText, "删除该条评论");
        mDialogUtil.setOnDialogListener(new AllDialogUtil.DialogOnClickListener() {
            @Override
            public void onConfirmClick(Dialog lDialog) {
                deleteTalkComment(comment);
                lDialog.dismiss();
            }

            @Override
            public void onCancelClick(Dialog lDialog) {
                lDialog.dismiss();
            }
        });
    }


}
